2 Problem: 11088 - End up with More Teams
3 Author: Andrés Mejía-Posada
4 (http://blogaritmo.factorcomun.org)
29 #define D(x) cout << #x " is " << x << endl
30 #define bit(i, n) (n & (1 << i))
32 int memo
[1<<15], x
[15], n
;
35 Returns the maximum amount of teams that can be made using
36 teams set on on bitwise mask avail. At each step, I try to
37 build a new team using the first available person, or igno-
38 re that person completely.
41 int &ans
= memo
[avail
];
44 for (int i
=0; i
<n
; ++i
)
46 ans
= max(ans
, best(avail
& ~(1 << i
))); //Ignore this dogg
47 for (int j
=i
+1; j
<n
; ++j
)
49 for (int k
=j
+1; k
<n
; ++k
)
51 if(x
[i
] + x
[j
] + x
[k
] >= 20)
52 ans
= max(ans
, 1 + best(avail
& ~(1 << i
) & ~(1 << j
) & ~(1 << k
))); //Make team (i, j, k).
56 //printf("best(%X) = %d\n", avail, ans);
62 while (scanf("%d", &n
) == 1 && n
){
63 for (int i
= 0; i
<n
; ++i
) scanf("%d", &x
[i
]);
65 memset(memo
, -1, sizeof memo
);
66 printf("Case %d: %d\n", pizza
++, best((1 << n
) - 1));